namespace ASPNET.StarterKit.IssueTracker
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using ASPNET.StarterKit.IssueTracker.UserInterfaceLayer;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class Notifications : UserControl, IIssueTab
    {
        [AccessedThroughProperty("btnNo")]
        private Button _btnNo;
        [AccessedThroughProperty("btnYes")]
        private Button _btnYes;
        [AccessedThroughProperty("grdNotifications")]
        private DataGrid _grdNotifications;
        private int _IssueId;
        private object designerPlaceholderDeclaration;

        public Notifications()
        {
            base.Init += new EventHandler(this.Page_Init);
            this._IssueId = 0;
        }

        public void AddNotification(object s, EventArgs e)
        {
            new IssueNotification(this.IssueId, this.Page.User.Identity.Name).Save();
            this.BindNotifications();
        }

        public void BindNotifications()
        {
            this.grdNotifications.DataSource = IssueNotification.GetIssueNotificationsByIssueId(this._IssueId);
            this.grdNotifications.DataBind();
        }

        public void DeleteNotification(object s, EventArgs e)
        {
            IssueNotification.DeleteIssueNotification(this.IssueId, this.Page.User.Identity.Name);
            this.BindNotifications();
        }

        public void Initialize()
        {
            this.BindNotifications();
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        int ASPNET.StarterKit.IssueTracker.UserInterfaceLayer.IIssueTab.IssueId
        {
            get
            {
                return this._IssueId;
            }
            set
            {
                this._IssueId = value;
            }
        }

        protected virtual Button btnNo
        {
            get
            {
                return this._btnNo;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnNo != null)
                {
                    this._btnNo.Click -= new EventHandler(this.DeleteNotification);
                }
                this._btnNo = value;
                if (this._btnNo != null)
                {
                    this._btnNo.Click += new EventHandler(this.DeleteNotification);
                }
            }
        }

        protected virtual Button btnYes
        {
            get
            {
                return this._btnYes;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnYes != null)
                {
                    this._btnYes.Click -= new EventHandler(this.AddNotification);
                }
                this._btnYes = value;
                if (this._btnYes != null)
                {
                    this._btnYes.Click += new EventHandler(this.AddNotification);
                }
            }
        }

        protected virtual DataGrid grdNotifications
        {
            get
            {
                return this._grdNotifications;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._grdNotifications != null)
                {
                }
                this._grdNotifications = value;
                if (this._grdNotifications != null)
                {
                }
            }
        }

        public int IssueId
        {
            get
            {
                return this._IssueId;
            }
            set
            {
                this._IssueId = value;
            }
        }
    }
}

